<?php

/****************************************************
DESCRIPTION: 	HOMEPAGE OPTIONS
OPTION HANDLE: 	canon_options_hp
****************************************************/


	/****************************************************
	REGISTER MENU
	****************************************************/

	add_action('admin_menu', 'register_canon_options_hp');

	function register_canon_options_hp () {
		global $screen_handle_canon_options_hp;	  	//this is the SCREEN handle used to identify the new admin menu page (notice: different than the add_menu_page handle)

		// Use this instad if submenu
		$screen_handle_canon_options_hp = add_submenu_page(
			'handle_canon_options',					//the handle of the parent options page. 
			'Homepage Settings',					//the submenu title that will appear in browser title area.
			'Homepage',								//the on screen name of the submenu
			'manage_options',						//privileges check
			'handle_canon_options_hp',				//the handle of this submenu
			'display_options_hp'				//the callback function to display the actual submenu page content.
		);

		//changing the name of the first submenu which has duplicate name (there are global variables $menu and $submenu which can be used. var_dump them to see content)
		// Put this in the submenu controller. NB: Not in the first add_menu_page controller, but in the first submenu controller with add_submenu_page. It is not defined until then. 
		global $submenu;	
		$submenu['handle_canon_options'][0][0] = "General";

	}

	/****************************************************
	INITIALIZE MENU
	****************************************************/

	add_action('admin_init', 'init_canon_options_hp');	
	
	function init_canon_options_hp () {
		register_setting(
			'group_canon_options_hp',					//group name. The group for the fields custom_options_group
			'canon_options_hp',						//the options variabel. THIS IS WEHERE YOUR OPTIONS ARE STORED.
			'validate_canon_options_hp'				//optional 3rd param. Callback /function to sanitize and validate
		);

		//if this is first runthrough set default values
		if (get_option('canon_options_hp') == FALSE) {		//trying to get options 'canon_options_hp' which doesn't yet exist results in FALSE
		 	$options = array (

		 			'show_features'					=> 'checked',
		 			'features'						=> array(
		 				0 								=> array(
			 				0 								=> array (
			 					'show'							=> 'checked',
			 					'font_awesome_icon'				=> 'fa-html5',
			 					'title'							=> 'Powder sugar wafer croissant stick.',
			 					'text'							=> 'Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Curabitur blandit tempus porttitor. Vestibulum id ligula porta felis euismod semper. Maecenas faucibus mollis interdum.',
			 				),
			 				1 								=> array (
			 					'show'							=> 'checked',
			 					'font_awesome_icon'				=> 'fa-html5',
			 					'title'							=> 'Powder sugar wafer croissant stick.',
			 					'text'							=> 'Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Curabitur blandit tempus porttitor. Vestibulum id ligula porta felis euismod semper. Maecenas faucibus mollis interdum.',
			 				),
			 				2 								=> array (
			 					'show'							=> 'checked',
			 					'font_awesome_icon'				=> 'fa-html5',
			 					'title'							=> 'Powder sugar wafer croissant stick.',
			 					'text'							=> 'Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Curabitur blandit tempus porttitor. Vestibulum id ligula porta felis euismod semper. Maecenas faucibus mollis interdum.',
			 				),
		 				),

		 				1 								=> array(
			 				0 								=> array (
			 					'show'							=> 'checked',
			 					'font_awesome_icon'				=> 'fa-html5',
			 					'title'							=> 'Powder sugar wafer croissant stick.',
			 					'text'							=> 'Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Curabitur blandit tempus porttitor. Vestibulum id ligula porta felis euismod semper. Maecenas faucibus mollis interdum.',
			 				),
			 				1 								=> array (
			 					'show'							=> 'checked',
			 					'font_awesome_icon'				=> 'fa-html5',
			 					'title'							=> 'Powder sugar wafer croissant stick.',
			 					'text'							=> 'Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Curabitur blandit tempus porttitor. Vestibulum id ligula porta felis euismod semper. Maecenas faucibus mollis interdum.',
			 				),
			 				2 								=> array (
			 					'show'							=> 'checked',
			 					'font_awesome_icon'				=> 'fa-html5',
			 					'title'							=> 'Powder sugar wafer croissant stick.',
			 					'text'							=> 'Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Curabitur blandit tempus porttitor. Vestibulum id ligula porta felis euismod semper. Maecenas faucibus mollis interdum.',
			 				),
		 				),


		 			),

		 			'use_hp_quotes' 				=> 'checked',
		 			'manual_quotes_as_tweets' 		=> 'unchecked',
		 			'hp_quotes_style' 				=> 'manual',
		 			'hp_num_tweets' 				=> 3,
		 			'hp_quotes'						=> array(
		 				'0' => array('Curabitur blandit tempus porttitor. Sed posuere consectetur est at lobortis.','Santa Claus'),
		 				'1' => array('Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas sed diam eget risus varius blandit sit amet non magna. Maecenas faucibus mollis interdum.','James Dean'),
		 				'2' => array('Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec sed odio dui.','Micky Dora'),
		 			),

				);

			update_option('canon_options_hp', $options);
		}
	}



	/****************************************************
	VALIDATE INPUT AND DISPLAY MENU
	****************************************************/

	//remember this will strip all html php tags, strip slashes and convert quotation marks. This is not always what you want (maybe you want a field for HTML?) why you might want to modify this part.	
	function validate_canon_options_hp ($new_instance) {				
		return $new_instance;
	}

	//display the menus
	function display_options_hp () {
		require "options_hp.php";
	}